<template>
  <div class="notice-box">
    <div class="notice-title-group">
      <div
        v-for="(title, index) in titles"
        :key="index"
        class="notice-title"
        :class="{ active: index == titleIndex }"
        @click="onChangeNotice(index)"
      >
        {{ title }}
      </div>
    </div>
    <div class="notice-content">
      <div class="notice-cover">
        <img :src="content.cover" alt="" />
      </div>
      <div class="notice-sub-title">{{content.title}}</div>
      <div class="notice-details">{{content.text}}</div>
      <div class="btn-see-detail" @click="onSeeDetail(content.path)"></div>
    </div>
  </div>
  <div class="notice-box-mobile">
    <div class="notice-card" v-for="content in contents" :key="content">
      <div class="notice-title">{{content.title}}</div>
      <div class="notice-cover">
        <img :src="content.cover" alt="" />
      </div>
      <div class="notice-content">
        <div class="notice-details">{{content.text}}</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, reactive, toRefs, inject } from "vue";
import { useRouter } from "vue-router";
import data from './notice.json'

export default defineComponent({
  name: "Notice",
  setup() {
    const closeDialog =  inject("closeDialog")
    const router = useRouter()
    const state = reactive({
      titleIndex: 0,
      titles: data.titles,
      contents: data.contents
    });

    const content = computed(() => {
      return state.contents[state.titleIndex]
    })

    function onChangeNotice(index) {
      state.titleIndex = index;
    }

    function onSeeDetail(path) {
      router.push(path)
      closeDialog()
    }

    return {
      ...toRefs(state),
      content,
      onChangeNotice,
      onSeeDetail
    };
  },
});
</script>

<style lang="scss" scoped>
.notice-box {
  display: flex;

  .notice-title-group {
    width: 170px;
    margin-top: 30px;
    margin-left: 9px;

    .notice-title {
      width: 166px;
      height: 46px;
      line-height: 46px;
      text-align: center;
      font-size: 16px;
      color: #d0cde8;
      font-weight: 600;
      margin-bottom: 5px;
      cursor: pointer;
    }

    .active {
      color: #ffea00;
      background-image: url(@/static/img/welfare/bg_notice_title.png);
      background-size: 166px 46px;
      background-repeat: no-repeat;
    }
  }

  .notice-content {
    margin: 16px;
    flex: 1;
    .notice-cover {
      width: 493px;
      img {
        width: 100%;
      }
    }

    .notice-sub-title {
      color: #3f75ff;
      font-size: 16px;
      font-weight: bold;
      margin-top: 10px;
      cursor: pointer;
    }

    .notice-details {
      display: block;
      display: -webkit-box;
      height: 220px;
      overflow: hidden;
      text-overflow: ellipsis;
      -webkit-line-clamp: 9;
      -webkit-box-orient: vertical;
      color: #d0cde8;
      font-size: 14px;
      line-height: 24px;
      padding-right: 10px;
    }

    .btn-see-detail {
      cursor: pointer;
      width: 259px;
      height: 68px;
      margin: 0 auto;
      background-image: url(@/static/img/welfare/btn_see_details.png);
      background-size: 100%;
    }
  }
}
.notice-box-mobile {
  display: none;
}

@media screen and (max-width: 768px) {
  .notice-box {
    display: none;
  }
  .notice-box-mobile {
    display: block;
    width: 100%;
    .notice-card {
      padding-left: 13px;
      padding-right: 13px;
      padding-top: 10px;

      .notice-title {
        height: 30px;
        line-height: 26px;
        text-align: center;
        background-image: url(@/static/img/welfare/bg_notice_title_line.png);
        background-size: 100%;
        background-position: center;
        color: #FFEA00;
      }

      .notice-cover {
        width: 100%;
        background-color: #110836;
        img {
          width: 100%;
        }
      }

      .notice-content {
        font-size: 12px;
        color: #d0cde8;
        height: auto;
        padding: 10px 15px 16px;
        background-color: #110836;
        .notice-details {
          display: block;
        display: -webkit-box;
        overflow: hidden;
        text-overflow: ellipsis;
        -webkit-line-clamp: 9;
        -webkit-box-orient: vertical;
        }
      }
    }
  }
}
</style>